#!/usr/bin/sh
echo "Mono Web Application deployment script"
echo " 	by Alexey Prey Mulyukin (c) 2016"
echo "  email: alexprey@yandex.ru"
echo ""

APP_BUILD_DIR=$1
APP_DEPLOY_DIR=$2

if [ -z $APP_BUILD_DIR -a -z $APP_DEPLOY_DIR ]; then
	echo "Usage: sh deployWebApplication.sh APP_BUILD_DIR APP_DEPLOY_DIR"
	echo "   APP_BUILD_DIR    directory with application binaries for deployment"
	echo "   APP_DEPLOY_DIR   destination directory for application deployment"
	exit 1
fi

if [ ! -d $APP_BUILD_DIR ]; then
	echo "Application directory '$APP_BUILD_DIR' not found"
	echo "Directory with builded application should be exists!"
	exit 1
fi

if [ ! -d $APP_DEPLOY_DIR ]; then
	echo "Deploy directory '$APP_DEPLOY_DIR' not found"
	echo "Directory for deploying should be exists!"
	exit 1
fi

echo "Application: '$APP_BUILD_DIR'"
echo "Deploy path: '$APP_DEPLOY_DIR'"

# Clear deploy directory from exists application
rm -Rf $APP_DEPLOY_DIR/*

# Copy application to deploy folder
cp -Rf $APP_BUILD_DIR/* $APP_DEPLOY_DIR

# Remove unsed files
rm -Rf $APP_DEPLOY_DIR/*.cs
rm -Rf $APP_DEPLOY_DIR/*.tt
rm -Rf $APP_DEPLOY_DIR/*.tt.*
rm -Rf $APP_DEPLOY_DIR/*.csproj
rm -Rf $APP_DEPLOY_DIR/bin/*.pdb
rm -Rf $APP_DEPLOY_DIR/bin/*.mdb

echo "Application '$APP_BUILD_DIR' successfully deployed to '$APP_DEPLOY_DIR'"
